package ChessBoard;

import java.util.ArrayList;


public class King extends Figure {

	public King(boolean isWhite, int[] position, ChessBoard board) {
		super(isWhite, position, board);
		super.value = 100;
	}

	@Override
	protected ArrayList<int[]> calculatePos() {
		super.resetAll();

		ArrayList<int[]> newMoves = new ArrayList<int[]>();
		for (int x = super.position[0] - 1; x < super.position[0] + 2; x++) {
			for (int y = super.position[1] - 1; y < super.position[1] + 2; y++) {
				if (x >= 1 && x <= 8 && y >= 1 && y <= 8) {
					if (super.correspondingBoard.fieldIsEmpty(new int[] { x, y }))
						newMoves.add(new int[] { x, y });
				}
			}
		}
		calculateKillsAndCovers();
		return newMoves;
	}

	protected void calculateKillsAndCovers() {
		for (int x = super.position[0] - 1; x < super.position[0] + 2; x++) {
			for (int y = super.position[1] - 1; y < super.position[1] + 2; y++) {
				if (x >= 1 && x <= 8 && y >= 1 && y <= 8) {
					if(!super.correspondingBoard.fieldIsEmpty(new int[]{x,y})){
						Figure f = super.correspondingBoard.getFigure(new int[] {
								x, y });
						if (super.isWhite == f.isWhite) {
							super.covers.add(f);
						} else {
							if (f.coveredBy == 0)
								super.kills.add(f);
						
					}}
				}
			}
		}
	}

	@Override
	public void checkCheck() {
		// TODO Auto-generated method stub

	}

}
